﻿using System;
using Quicklight.Web.Html;
using System.Html;

namespace Quicklight.Web.Razor {

   /// <summary>
   /// Does the binding on behalf of a declarative binding of a ElementEventHandler delegate to an event of an element
   /// </summary>
   public class ElementEventHandlerBinder : EventBinder {
      private ElementEventHandler elementEventHandler;

      /// <summary>
      /// Constructs a ElementEventHandlerBinder for binding the ElementEventHandler to the event of an element 
      /// </summary>
      /// <param name="eventName">Name of the event to bind to</param>
      /// <param name="elementEventHandler">Delegate ElementEventHandler to bind to event</param>
      public ElementEventHandlerBinder(string eventName, ElementEventHandler elementEventHandler)
         : base(eventName) {
            this.elementEventHandler = elementEventHandler;
      }

      /// <summary>
      /// Bind method does the actual binding of the ElementEventHandler to the event of the specified element
      /// </summary>
      /// <param name="element">Element with which the binding must occur</param>
      protected override void Bind(Element element) {
         element.Bind(eventName, elementEventHandler);
      }
   }
}
